package com.lu.servlet;

import com.lu.entity.NewsUsers;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class LoginoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        List<NewsUsers> currentUserList = (List<NewsUsers>) req.getServletContext().getAttribute("currentUserList");
        NewsUsers currentUser = (NewsUsers) req.getSession().getAttribute("currentUser");
        currentUserList.remove(currentUser);
        // 退出 就是从会话中删除我的数据
        req.getSession().removeAttribute("currentUser");

        resp.sendRedirect("index.jsp");

        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
